/**
 * @author Caius
 * @description 定义rabbitMQ的相关配置
 * @version 1.0
 * @since Created in 2025-01-17
 */

package com.itsense.stock.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {
    @Bean
    public MessageConverter messageConverter(){
        return new Jackson2JsonMessageConverter();
    }

    /**
     * 定义主题交换机
     * @return
     */
    @Bean
    public TopicExchange stockTopicExchange(){
        return new TopicExchange("stockExchange",true,false);
    }

    /**
     * 定义消息队列
     * @return
     */
    @Bean
    public Queue innerMarketQueue(){
        return new Queue("innerMarketQueue",true);
    }

    /**
     * 绑定国内大盘队列到股票主题交换机
     * @return
     */
    @Bean
    public Binding bindingInnerMarketQueue(){
        return BindingBuilder.bind(innerMarketQueue()).to(stockTopicExchange()).with("inner.market");
    }

}
